<?php

require_once './core/tools.php';

$databaseConnectionError = @dbConnect($_POST["dbhost"], $_POST["dbuser"], $_POST["dbpwd"], $_POST["dbname"]);

if ($databaseConnectionError == "ok") {
	$data = array(
             'dbhost' => $_POST["dbhost"],
             'dbname' => $_POST["dbname"],
             'dbuser' => $_POST["dbuser"],
             'dbpwd' => $_POST["dbpwd"]
             );


	if (write_ini_file($data)) {

		$handle = fopen(DATABASE_SQL, "r");
		
		while(!feof($handle)) {
			if (!executeSQL(fgets($handle))){
				include "./core/template.php";
				echo getErrorPage(4);	
				return;
			} 
		}

		fclose($handle);		

		include "./install-step3.php";
	}
	else {
		include "./core/template.php";
		echo getErrorPage(1);
	}
}
else {
	include "./core/template.php";
	echo getErrorPage(2, $databaseConnectionError);
}



@dbDisconnect();

?>